<!-- 日志管理 -->
<template>
  <div id="template">
    <page-main>
      <avue-crud v-model="Main_Form" :option="Main_Option" :data="Main_Data" :page.sync="Main_Page"
        :search.sync="Main_search" :table-loading="main_table_loading" ref="crud" @refresh-change="refreshChange"
        @search-change="searchChange" @reset-change="resetChange" @row-update="rowUpdate"
        @size-change="sizeChange" @current-change="currentChange">
      </avue-crud>
    </page-main>
  </div>
</template>

<script>
import { Main_Option, Main_Data } from "./config";
import {
  queryJournalApi
} from '@/api/journal/index';

export default {
  data () {
    return {
      Main_Option,
      Main_Data,
      main_table_loading: false,
      Main_Form: {},
      Main_search: {},
      Main_Page: {
        currentPage: 1,
        pageSize: 10,
        total: 1,
      },
    };
  },
  mounted () {
    this.getHomePageInfoFunc();
  },
  methods: {
    // 搜索事件
    async searchChange (params, done) {
      await this.getHomePageInfoFunc();
      done();
    },
    // 重置
    resetChange () {
      this.Main_search = {};
    },
    // 刷新
    refreshChange () {
      this.Main_Page.currentPage = 1;
      this.getHomePageInfoFunc();
    },

    currentChange (val) {
      this.Main_Page.currentPage = val;
      this.getHomePageInfoFunc();
    },

    sizeChange (val) {
      this.Main_Page.pageSize = val;
      this.getHomePageInfoFunc();
    },

    /**
     * @name requests
     * @author --h28
     */
    // 获取主页
    async getHomePageInfoFunc () {
      this.main_table_loading = true;
      const response = await queryJournalApi({
        ...this.Main_search,
        currentPage: this?.Main_Page?.currentPage ?? 1,
        pageSize: this?.Main_Page?.pageSize ?? 10,
      }).catch(() => { });
      
      if (response?.code === 200) {
        this.Main_Data = response?.data?.records ?? [];
        this.Main_Page.total = response?.data?.total ?? 0;
      }
      this.main_table_loading = false;
    },
  },
};
</script>

  <!-- <style>

  </style> -->
